package com.atguigu.bean;

/**
 * @author : leimingchao
 * @version V1.0
 * @Project: mybatis
 * @Package com.atguigu.bean
 * @Description: TODO
 * @date Date : 2021年05月23日 13:12
 * 希望数据库保存的是100,200这些状态码，而不是默认0,1或者枚举名
 */
public enum EmployeeStatus {
    LOGIN(100, "用户登录"), LOGOUT(200, "用户登出"), REMOVE(300, "用户不存在");

    private Integer code;
    private String msg;

    private EmployeeStatus(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    /**
     * 根据状态码返回枚举对象
     *
     * @param code
     * @return
     */
    public static EmployeeStatus getEmployeeStatusByCode(Integer code) {
        switch (code) {
            case 100:
                return LOGIN;
            case 200:
                return LOGOUT;
            case 300:
                return REMOVE;
            default:
                return LOGOUT;
        }
    }
}
